package com.tuniu.agents.tools.train.enums;

import com.tuniu.agents.util.I18nUtil;

import java.util.Arrays;

/**
 * train solution
 */
public enum TrainSolutionEnum {
    TRANSFER("transfer", "train.template.transfer","train.template.transfer.desc"),
    SEGMENT("addition", "train.template.addition","train.template.addition.desc"),
    DIRECT("direct", "train.template.direct",null);

    private final String type;
    private final String solution;
    private final String desc;

    TrainSolutionEnum(String type, String solution,String desc) {
        this.type = type;
        this.solution = solution;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public String getSolution(String conversationId) {
        return I18nUtil.getMessage(conversationId,solution);
    }

    public String getDesc() {
        return desc;
    }

    public static String getSolutionByType(String type,String conversationId) {
        return Arrays.stream(values())
                .filter(solution -> solution.type.equals(type))
                .findFirst()
                .map(trainSolutionEnum -> {
                    return trainSolutionEnum.getSolution(conversationId);
                })
                .orElse(DIRECT.solution);  // default return
    }

    public static String getDescByType(String type, String conversationId) {
        return Arrays.stream(values())
                .filter(solution -> solution.type.equals(type))
                .findFirst()
                .map(trainSolutionEnum ->
                        trainSolutionEnum.desc != null ?
                                I18nUtil.getMessage(conversationId, trainSolutionEnum.desc) :
                                ""
                )
                .orElse(type);  // default return
    }

}
